package org.begincode.course.service;

import com.begincode.common.constant.Constant;
import org.begincode.core.mapper.VideoChapterMapper;
import org.begincode.core.mapper.WordChapterMapper;
import org.begincode.core.model.VideoChapter;
import org.begincode.core.model.VideoChapterExample;
import org.begincode.core.model.WordChapter;
import org.begincode.core.model.WordChapterExample;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by yangsj on 2016/5/1.
 */
@Service
public class ChapterService {
    @Resource
    private WordChapterMapper wordChapterMapper;
    @Resource
    private VideoChapterMapper videoChapterMapper;

    public List<WordChapter> selectWordChaptersByCourseId(int courseId){
        WordChapterExample wordChapterExample = new WordChapterExample();
        wordChapterExample.createCriteria()
                .andDeleteFlagEqualTo(Constant.NO_DEL_FLAG)
                .andCourseIdEqualTo(courseId);
        wordChapterExample.setOrderByClause(" order_num ");
        return wordChapterMapper.selectByExample(wordChapterExample);
    }

    public WordChapter selectWordChapterById(int chapterId){
        return wordChapterMapper.selectByPrimaryKey(chapterId);
    }


    public List<VideoChapter> selectVideoChapters(int courseId){
        VideoChapterExample videoChapterExample = new VideoChapterExample();
        videoChapterExample.createCriteria()
                .andDeleteFlagEqualTo(Constant.NO_DEL_FLAG)
                .andCourseIdEqualTo(courseId);
        return videoChapterMapper.selectByExample(videoChapterExample);
    }



}
